// CustomDBVariable.cpp: implementation of the CCustomDBVariable class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "CustomDBVariable.h"
#include "PropertyVisitor.h"
#include "PropertyExpression.h"
#include "PropertyOwner.h"

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
namespace pa
{
	CustomDBVariable::CustomDBVariable()
	{

		PropertyVar(this);
		m_bIsCustom = true;
	}

	CustomDBVariable::~CustomDBVariable()
	{

	}

	Property* CustomDBVariable::Clone()
	{
		CustomDBVariable *pVar = new CustomDBVariable;
		ASSERT(pVar);

		this->CopyCustomData(*pVar,*this);
		this->CopyPropertyData(*pVar,*this);
		pVar->PropertyTable(this->PropertyTable());
		pVar->PropertyField(this->PropertyField());
		return pVar;
	}

	void CustomDBVariable::UpdateData()
	{
		m_EffectData.RemoveAll();
		
		if(PromptSource().IsEmpty())
		{
			return;
		}

		PropertyExpression expr(PromptSource(), GetOwner()->GetPropertyContainer());

		Variable var = expr.Caculate();

		StdString strSql;
		strSql = (StdString)var;		

		UEConnectionPtr pConnectionPtr = UEConnectionManager
							::Instance().GetConnection(Source());
         OriginalPropertySet pPropertySet 
							= pConnectionPtr->ExecuteSelectSQL(strSql);
		 pPropertySet->MoveFirst();
		 
		 while(!pPropertySet->IsEOF())
		 {
			 m_EffectData.Add(pPropertySet->GetString(this->PropertyField()));
			 pPropertySet->MoveNext();
		 }


	}

	BOOL CustomDBVariable::Accept(PropertyVisitor& visitor)
	{
		return visitor.Visit(this);
	}
};